select @commonDept:=DepartmentId from Department where Name='Common';
select @userRole:=DcRoleId from DcRole where RoleName='Users';
select @adminRole:=DcRoleId from DcRole where RoleName='Administrators';
select @docCircAdmin:=DcUserId from DcUser where Login='DocCircAdmin';

insert into dcuser (DcUserId, Login, Password, FullName, AutomaticPass, AllowDeputyNotification, Department, 
	InstantMessaging, ImAddress, ChangePwdNextTime, ExternalAuthorization, ExternalIdentity) values   
	(default, 'TestUser1', password('1'),'Test Test User1', false, true, @commonDept, true, 'testuser1@im.test.org', false, false, '');  
set @User1Id:=last_insert_id();  
insert into UserEmail (DcUser,UserEmail) values (@User1Id, 'test11@test.ru'),  
	(@User1Id, 'test12@test.ru');  

insert into DcUser (DcUserId, Login, Password, FullName, AutomaticPass, AllowDeputyNotification, Department, 
	InstantMessaging, ImAddress, ChangePwdNextTime, ExternalAuthorization, ExternalIdentity) values   
	(default, 'TestUser2', password('2'), 'Test Test User2', true, true, @commonDept, false, '', false, false, 'TEST\\TestUser2');  
set @User2Id = last_insert_id();  
insert into UserEmail (DcUser,UserEmail) values (@User2Id, 'test21@test.ru'),  
	(@User2Id, 'test22@test.ru'), (@User2Id, 'test23@test.ru');  

insert into dcuser (DcUserId, Login, Password, FullName, AutomaticPass, AllowDeputyNotification, Department, 
	InstantMessaging, ImAddress, ChangePwdNextTime, ExternalAuthorization, ExternalIdentity) values   
	(default, 'TestUser3', password('3'), 'Test Test User3', false, true, @commonDept, true, 'testuser3@im.test.org', false, false, 'TEST\\TestUser3');  
set @User3Id = last_insert_id();   -- user doesn't have emails

insert into DcRole (DcRoleId, RoleName) values (default, 'TestUsers'); 
set @TestUsersRoleId = last_insert_id();  -- TestUsers role added
insert into dcrole (DcRoleId, RoleName) values (default, 'TestUsers2');  -- TestUsers2 role added
set @TestUsers2RoleId = last_insert_id(); 
insert into roleToUser (DcRole, DcUser, Position) values (@TestUsersRoleId, @User2Id, 1);   -- User2 added to TestUsers role
insert into roleToUser (DcRole, DcUser, Position) values (@TestUsers2RoleId, @User2Id, 2);  -- User2 added to TestUsers2 role
insert into roleToUser (DcRole, DcUser, Position) values (@TestUsersRoleId, @User3Id, 1);   -- User3 added to TestUsers role

-- insert deputies for TestUser3
insert into Deputy (DcUser, Deputy, Notify) Values (@User3Id, @User1Id, true);
set @user3Deputy1=last_insert_id();
insert into Deputy (DcUser, Deputy, Notify) Values (@User3Id, @User2Id, true);
set @user3Deputy2=last_insert_id();